<!DOCTYPE html>
<html lang="en">
<style>
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
    input[type=checkbox], input[type=radio] {
        display: inline-block;
    }
</style>

{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper" >
        <div class="row-content am-cf">
            <div class="row">

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-8">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">{notempty name='$data'}编辑{else}新增{/notempty}</div>
                            <div class="widget-function am-fr">
                                <a href="javascript:;" class="am-icon-cog"></a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">

                            <form id="roleform" form="submit" class="am-form tpl-form-border-form tpl-form-border-br">
                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">账号</label>
                                    <div class="am-u-sm-6">
                                        <input type="text" class="tpl-form-input" name="mobile" placeholder="请输入账号(手机号)" value="{notempty name='$data'}{$data.mobile}{/notempty}">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                </div>



                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">密码</label>
                                    <div class="am-u-sm-6">
                                        <input type="password" class="tpl-form-input"{notempty name='$data'}name="password2" {else}name="password"{/notempty} placeholder="{notempty name='$data'}需要修改时输入{else}请输入密码{/notempty}" value="">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">用户姓名</label>
                                    <div class="am-u-sm-6">
                                        <input type="text" class="tpl-form-input" name="name" placeholder="请输入用户姓名" value="{notempty name='$data'}{$data.name}{/notempty}">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                </div>

                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">地址</label>
                                    <div class="am-u-sm-6" style="float: left;">
                                        <input type="text" name="address" class="tpl-form-input" value="{notempty name='$data'}{$data.address}{/notempty}" placeholder="输入地址">
                                        <small>如果没有搜索到你想要的地点，可以选择较近的地点，更改详细地址，本定位仅用于判断订单距离</small>
                                    </div>

                                </div>
                                <div class="am-form-group">
                                    <!--地址弹窗-->
                                    <label for="user-name" class="am-u-sm-3 am-form-label"></label>
                                    <div class="am-u-sm-5 diz_window">
                                        <ul>

                                        </ul>
                                    </div>
                                </div>
                                <div class="am-form-group">
                                    <label for="user-name" class="am-u-sm-3 am-form-label">经度</label>
                                    <div class="am-u-sm-2">
                                        <input type="text" class="tpl-form-input" name="longitude"  placeholder="输入经度" value="{notempty name='$data'}{$data.longitude}{/notempty}">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                    <label for="user-name" class="am-u-sm-1 am-form-label">纬度</label>
                                    <div class="am-u-sm-2">
                                        <input type="text" class="tpl-form-input" name="latitude"  placeholder="输入纬度" value="{notempty name='$data'}{$data.latitude}{/notempty}">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                    <label for="user-name" class="am-u-sm-1 am-form-label">省</label>
                                    <div class="am-u-sm-2">
                                        <input type="text" class="tpl-form-input" name="provinceName"  placeholder="输入省" value="{notempty name='$data'}{$data.provinceName}{/notempty}">
                                        <!--<small>请填写6位以上英文或数字。</small>-->
                                    </div>
                                </div>

                                <!--<div class="am-form-group">-->
                                    <!--<label for="user-name" class="am-u-sm-3 am-form-label">折扣率 </label>-->
                                    <!--<div class="am-u-sm-5">-->
                                        <!--<input type="number" class="tpl-form-input" name="discount" placeholder="请输入折扣率" value="{notempty name='$data'}{$data.discount}{/notempty}">-->
                                        <!--<small>折扣率单位为百分比，如输入90，表示该账户可以以商品原价的90%购买。</small>-->
                                    <!--</div>-->
                                <!--</div>-->



                                <div class="am-form-group">
                                    <div class="am-u-sm-9 am-u-sm-push-3">
                                        <a onclick="javascript:history.back(-1);" ><input class="btn btn-default" type="reset" value="返回">&nbsp;&nbsp;&nbsp;&nbsp;</a>
                                        {notempty name='$data'}
                                        <input type="hidden" name="id" value="{$data.id}">
                                        {/notempty}
                                        <input class="btn btn-info" type="submit"  value="提交">
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>

{include file='Public:script'}
{include file='Public:validation'}
<script>
    $(function () {
        $(document).on('input propertychange','[name="address"]', function() {
            search2();
        });
    });
    //搜索地址和经纬度
    function search2(t){
        var formData=[];

        formData['keywords']=$('[name="address"]').val();
        $.ajax({
            url:"https://addr.vmall.com/data/searchByKeywords.json",
            type:'GET',
            data:{'keywords':formData['keywords']},
            dataType:'jsonp',
            success:function(res){
                // if (res.success==false){
                //     layer.msg(res.msg, {shade: 0.5, time: 1000,icon: 2});
                // }
                if (res.data.length<1){
                    return false
                }
                var html='';
                $.each(res.data,function ($k,$v) {
                    html+=' <li onclick="select_site(\''+$v.provinceName+$v.cityName+$v.distinctName+$v.name+'\',\''+$v.location+'\',\''+$v.provinceName+'\')">\n' +
                        '      <span>'+$v.name+'</span><br>\n' +
                        '      <span>'+$v.provinceName+$v.cityName+$v.distinctName+'</span>\n' +
                        // '      <button type="button" class="am-btn am-btn-danger am-btn-xs" onclick="select_site(\''+$v.provinceName+$v.cityName+$v.distinctName+$v.name+'\',\''+$v.location+'\',\''+$v.provinceName+'\')">选择</button>\n' +

                        '<hr>' +
                        '  </li>';

                    $(".diz_window ul").html(html)
                })
            }
        });
    }
    //选择地址
    function select_site($dz,$location,$provinceName) {

        $(".diz_window ul").html('');
        var arr = $location.split(',');
        $('[name="address"]').val($dz);
        $('[name="provinceName"]').val($provinceName);
        $('[name="longitude"]').val(arr[0]);
        $('[name="latitude"]').val(arr[1]);

    }
    //获得经纬度
    function get_gwd() {
        $province= $('[name="province"]').find("option:selected").text();
        $city= $('[name="city"]').find("option:selected").text();
        $district= $('[name="district"]').find("option:selected").text();
        $address= $('input[name="address"]').val();
        if ($address==''){
            layer.msg('请填写详细地址', {shade: 0.5, time: 2000,icon: 2});
        }
        $address=$province+$city+$district+$address;
        var param = new Object();
        //(省)父id
        param['address']  = $address;
        $.post("{:url('Common/location2')}", param, function (res) {
            if (res.length<1) {
                layer.msg('请认真填写地址信息', {shade: 0.5, time: 2000,icon: 2});
            }
            $('input[name="address"]').val(res[0]['addr']);
            $('input[name="longitude"]').val(res[0]['pointx']);
            $('input[name="latitude"]').val(res[0]['pointy']);
        });


    }
    function get_city(t){
        var param = new Object();
        //(省)父id
        param['parent_id']   = $("[name='province']").val();
        param['level']   = '2';
        $.post("{:url('Common/getRegion')}", param, function (res) {
            res = '<option value="">选择市</option>'+res;
            $('[name="city"]').html(res);
        });

    }
    //获得县、区内容
    function get_area(t){
        var param = new Object();
        //(省)父id
        param['parent_id']   = $("[name='city']").val();
        param['level']   = '3';
        $.post("{:url('Common/getRegion')}", param, function (res) {
            res = '<option value="">选择县、区</option>'+res;
            $('[name="district"]').html(res);
        });

    }
    //提交
    function roleSubmit(){
        var form=document.getElementById("roleform");
        var formData=new FormData(form);
        $.ajax({
            url:"{:Url('addData')}",
            type:'POST',
            data:formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success:function(res){
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000,icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                    window.location.href=document.referrer;

                });
            }
        });
    }
</script>

</html>